﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
		<link rel="stylesheet" href="assets/front/css/xmlist.css" />
		<script src="/assets/front/js/jquery-1.12.4.min.js"></script>
		

						<div class="userd userinfo2" >
							<div class="u-top">
								<ul class="ut-box clear userinfo-boxval">
									<li class="hov5 hoved">个人信息</li>
									<li class="">安全设置</li>
								</ul>
							</div>
							<div class="u-cont">
								<div class="usercont" style="dis-play:none;">
									<form action="" class="form-upbox form-add" id="form-upbox1" enctype="multipart/form-data">
										<div class="formchange">
											<div class="lable clear">
												<p class="labname">用户名:</p>
												<input type="text"  class="inputval sur6" name="userName">
											</div>
											<input type="text" style="display:none;" class="inputval calssid" name="id">
											<div class="lable clear">
												<p class="labname">手机:</p>
												<input type="text"  class="inputval sur6" name="phone">
											</div>
											<div class="lable clear">
												<p class="labname">邮箱:</p>
												<input type="text"  class="inputval sur6" name="email">
											</div>
											<div class="zhixian"></div>
											<div class="lable clear">
												<p class="labname">真实姓名:</p>
												<input type="text"  class="inputval sur6" name="realname">
											</div>
											<div class="lable clear" style="font-size:12px;">
												<p class="labname">性别:</p>
												<input type="radio"  class="rad sex" value="0" name="sex">男
												<input type="radio"  class="rad sex" value="1" name="sex">女
											</div>
											<div class="lable clear">
												<p class="labname">地址:</p>
												<input type="text"  class="inputval sur6" name="address">
											</div>
											<div class="lable">
												<p class="labname">单位:</p>
												<input type="text"  class="inputval sur6" name="companyName">
											</div>
											<div class="lable clear">
												<p class="labname">职位:</p>
												<input type="text"  class="inputval sur6" name="jobName">
											</div>
											<div class="btnchan">
												修改信息
											</div>
										</form>
									</div>
								</div>
								<div class="usercont" style="display:none;">
									<div class="changpas">
										<div class="lable clear">
											<p class="labname">原密码:</p>
											<input type="password" class="inputval sur5">
										</div>
										<div class="lable clear">
											<p class="labname">新密码:</p>
											<input type="password" class="pas21 inputval sur5">
										</div>
										<div class="lable clear">
											<p class="labname">确认密码:</p>
											<input type="password" class="pas22 inputval sur5">
										</div>
										<div class="btnchan">
											修改密码
										</div>
										<p class="baocuo" style="font-size:14px;margin-top:20px;color:red;text-align:left;margin-left:100px;"></p>
									</div>
								</div>
							</div>
						</div>
			
			<script>
				$('.ut-box li').bind('click',function(){
					$(this).addClass('hov5').siblings('li').removeClass('hov5');
					$('.usercont').eq($(this).index()).css({'display':'block'}).siblings('.usercont').css({'display':'none'})
				})
				// 修改密码
				var usersdid = '';
				//修改密码验证
				$('.changpas .btnchan').bind('click',function(){
					var onf4 = true;
					$('.sur5').each(function(i,e){
						if(e.value == ''){
							e.focus();
							$('.sur5').eq(i).css({'border-bottom':'2px solid #b99663'});
							$('.baocuo').html('输入框内容不能为空');
							onf4 = false;
							return false
						}
					})
					if($('.pas21').val()!=$('.pas22').val()){
						$('.pas21').focus();
						$('.pas21').css({'border-bottom':'2px solid #b99663'});
						$('.baocuo').html('两次输入密码不同');
						onf4 = false;
						return false
					}
					if(onf4){
						var jk = common.Interface('changepas')[0];
						$.ajax({
								url : jk,
								data:{
									'oldPassword':$('.sur5').eq(0).val(),
									'newPassword':$('.sur5').eq(1).val()
								},
								type: "POST",
								error: function(request) {
									console.log(request)
								},
								dataType:"json",
								success: function(data) {
									if(data.ret){
										$('.baocuo').html('密码修改成功,请登陆');
										window.location.reload();
									}else{
										$('.baocuo').html(data.errmsg);
									}
								}
						})
					}
				})
				
				$('.changpas input').on('input',function(){
					$(this).css({'border-bottom':'2px solid #cdcdcd'})
					$('.baocuo').html('')
				})
				
				$.ajax({
					url : '/api/user/getUserId.json',
					type: "POST",
					error: function(request) {
						//console.log(request)
					},
					dataType:"json",
					success: function(data) {
						usersdid = data;
						userid = data;
						// 获取用户数据
					    var userurl= 'api/user/queryUserInfo.json?userId='+userid
						$.ajax({
							url : userurl,
							type: "POST",
							error: function(request) {
								//console.log(request)
							},
							dataType:"json",
							success: function(data) {
								
								if(data.ret){
									var data = data.data;
									$('.sur6').eq(0).val(data.userName)
									$('.sur6').eq(1).val(data.phone)
									$('.sur6').eq(2).val(data.email)
									$('.sur6').eq(3).val(data.realname)
									$('.sur6').eq(4).val(data.address)
									$('.sur6').eq(5).val(data.companyName)
									$('.sur6').eq(6).val(data.jobName)
									$('.calssid').val(data.id)
									$('.sex').eq(data.sex).attr("checked",'checked');
								}
							}
						})
					}
				})
				
				// 修改个人中心
				$('#form-upbox1 .btnchan').bind('click',function(){
					var jkchange = 'api/user/updateUserInfo.json'
					$.ajax({
							url : jkchange,
							data:$("#form-upbox1").serialize(),
							type: "POST",
							error: function(request) {
								console.log(request)
							},
							dataType:"json",
							success: function(data) {
								
							}
					})
				})
				
			</script>
